package com.abcdefg.rabbitmqextensionsdemo.listener;

import com.abcdefg.rabbitmqextensionsdemo.constants.Constant;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

@Component
public class DlListener {
//    @RabbitListener(queues = Constant.NORMAL_QUEUE)
//    public void normallisten(Message message, Channel channel) throws IOException {
//        long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        try {
//
//            System.out.printf("[normal.queue]接收到的消息：%s,deliveryTag：%d\n", new String(message.getBody())
//                    , message.getMessageProperties().getDeliveryTag());
//            System.out.println("处理业务逻辑！！！");
//            int sum = 10 / 0;
//            System.out.println("处理完成！！！");
//            channel.basicAck(deliveryTag, false);
//        } catch (Exception e) {
//            //进行异常确认
//            channel.basicNack(deliveryTag, false, false);
//        }
//    }

    @RabbitListener(queues = Constant.DL_QUEUE)
    public void dllisten(Message message) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.printf("[dl.queue] %tc 接收到的消息：%s,deliveryTag：%d\n", new Date(),new String(message.getBody())
                , message.getMessageProperties().getDeliveryTag());
    }
}
